package com.wk.arth.od;

import java.util.*;

/**
 * 输入：5
 *             1 2 2 4 1
 * 输出：2
 * 说明：频度最高的有1和2，频度是2（出现的次数都是2）。可以包含频度最高的记录数组是[2 2]和[1 2 2 4 1]，最短是[2 2]，最小长度为2
 * @author wukai
 * @date 2023/4/19 18:27
 */
public class Tongxin_wu_ma {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        String[] list = sc.nextLine().split(" ");
        Map<String,Integer> map = new HashMap<>();
        for (int i = 0; i < list.length; i++) {
            map.put(list[i],map.getOrDefault(list[i],0)+1);
        }
        List<String> gaoPin = new ArrayList<>();
        int pin = 0;
        for (Map.Entry<String, Integer> entry : map.entrySet()) {
            if(entry.getValue() > pin){
                gaoPin.clear();
                gaoPin.add(entry.getKey());
                pin = entry.getValue();
            }else if(entry.getValue() == pin){
                gaoPin.add(entry.getKey());
            }
        }
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < list.length; i++) {
            for (int j = i+pin-1; j < list.length; j++) {
                int curMin = getCount(list,i,j,pin);
                if(curMin > -1){
                    min = Integer.min(min,curMin);
                    break;
                }
            }
        }
       if(min>n){
           System.out.println("errot");
       }else{
           System.out.println(min);
       }

    }
    private static int getCount(String[] list,int start,int end,int pin){
        int max = 0;
        Map<String,Integer> map = new HashMap<>();
        for (int i = start;i<=end;i++){
            int subPin = map.getOrDefault(list[i],0)+1;
            map.put(list[i],subPin);
            max = Integer.max(max,subPin);
        }
        if(max == pin){
            return end-start+1;
        }
        return -1;
    }
}
